package com.softqin.washer.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class WashDbHelper extends SQLiteOpenHelper{

	public static final String DB_NAME = "wash";
	
	public WashDbHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		createAddressTb(db);
		createCarTb(db);
		createBusinessTb(db);
		createServiceTb(db);
		createOrderTb(db);
		createRechargeRecordTb(db);
		createCommentTb(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
	}
	
	/**
	 * 创建地址表
	 * @param db
	 */
	private void createAddressTb(SQLiteDatabase db) {
		String sql_address_create = "create table if not exists " + WashDB.ADDRESS_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.ADDRESS_TB.TOKEN_ID + " text,"
				+ WashDB.ADDRESS_TB.ADDRESS + " text,"
				+ WashDB.ADDRESS_TB.DRIVER_ID + " text);";
		db.execSQL(sql_address_create);
	}
	
	/**
	 * 创建汽车表
	 * @param db
	 */
	private void createCarTb(SQLiteDatabase db) {
		String sql_car_create = "create table if not exists " + WashDB.CAR_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.CAR_TB.TOKEN_ID + " text,"
				+ WashDB.CAR_TB.DRIVER_ID + " text,"
				+ WashDB.CAR_TB.NUMBER + " text,"
				+ WashDB.CAR_TB.TYPE + " text,"
				+ WashDB.CAR_TB.BRAND + " text,"
				+ WashDB.CAR_TB.COLOR + " text,"
				+ WashDB.CAR_TB.PIC + " text,"
				+ WashDB.CAR_TB.BUYDATE + " text);";
		db.execSQL(sql_car_create);
	} 
	
	/**
	 * 创建商家表
	 * @param db
	 */
	private void createBusinessTb(SQLiteDatabase db) {
		String sql_business_create = "create table if not exists " + WashDB.BUSINESS_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.BUSINESS_TB.TOKEN_ID + " text,"
				+ WashDB.BUSINESS_TB.PHONE + " text,"
				+ WashDB.BUSINESS_TB.NAME + " text,"
				+ WashDB.BUSINESS_TB.QQ + " text,"
				+ WashDB.BUSINESS_TB.SEX + " text,"
				+ WashDB.BUSINESS_TB.EMAIL + " text,"
				+ WashDB.BUSINESS_TB.AGE + " integer,"
				+ WashDB.BUSINESS_TB.ADDRESS + " text,"
				+ WashDB.BUSINESS_TB.CREATED_TIME + " text,"
				+ WashDB.BUSINESS_TB.STATUS + " integer,"
				+ WashDB.BUSINESS_TB.LATITUDE + " text,"
				+ WashDB.BUSINESS_TB.LONGTITUDE + " text);";
		db.execSQL(sql_business_create);
	}
	
	/**
	 * 创建服务表
	 * @param db
	 */
	private void createServiceTb(SQLiteDatabase db) {
		String sql_service_create = "create table if not exists " + WashDB.SERVICE_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.SERVICE_TB.TOKEN_ID + " text,"
				+ WashDB.SERVICE_TB.BUSINESS_ID + " text,"
				+ WashDB.SERVICE_TB.CONTENT + " text,"
				+ WashDB.SERVICE_TB.PICS + " text,"
				+ WashDB.SERVICE_TB.PRICE + " text);";
		db.execSQL(sql_service_create);
	}
	
	/**
	 * 创建订单表
	 * @param db
	 */
	private void createOrderTb(SQLiteDatabase db) {
		String sql_order_create = "create table if not exists " + WashDB.ORDER_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.ORDER_TB.TOKEN_ID + " text,"
				+ WashDB.ORDER_TB.SERVICE_ID + " text,"
				+ WashDB.ORDER_TB.DRIVER_ID + " text,"
				+ WashDB.ORDER_TB.BUSINESS_ID + " text,"
				+ WashDB.ORDER_TB.CAR_ID + " text,"
				+ WashDB.ORDER_TB.ADDRESS_ID + " text,"
				+ WashDB.ORDER_TB.CREATEDDATE + " text,"
				+ WashDB.ORDER_TB.DESCRIPTION + " text);";
		db.execSQL(sql_order_create);
	}
	
	/**
	 * 创建支付记录表
	 * @param db
	 */
	private void createRechargeRecordTb(SQLiteDatabase db) {
		String sql_recharge_record_create = "create table if not exists " + WashDB.RECHARGE_RECORD_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.RECHARGE_RECORD_TB.TOKEN_ID + " text,"
				+ WashDB.RECHARGE_RECORD_TB.DRIVER_ID + " text,"
				+ WashDB.RECHARGE_RECORD_TB.MONEY + " float,"
				+ WashDB.RECHARGE_RECORD_TB.CREATEDDATE + " text);";
		db.execSQL(sql_recharge_record_create);
	}
	
	/**
	 * 创建评论表
	 * @param db
	 */
	private void createCommentTb(SQLiteDatabase db) {
		String sql_comment_create = "create table if not exists " + WashDB.COMMENT_TB.TABLE_NAME + "(_id integer primary key autoincrement,"
				+ WashDB.COMMENT_TB.TOKEN_ID + " text,"
				+ WashDB.COMMENT_TB.ORDER_ID + " text,"
				+ WashDB.COMMENT_TB.DRIVER_ID + " text,"
				+ WashDB.COMMENT_TB.BUSINESS_ID + " text,"
				+ WashDB.COMMENT_TB.COMMENT + " text,"
				+ WashDB.COMMENT_TB.NAME + " text,"
				+ WashDB.COMMENT_TB.CREATETIME + " text);";
		db.execSQL(sql_comment_create);
	}
	
	
	
	
	


}
